package org.example.new_hbps_backend_reconstruction.config;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;

import java.io.IOException;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;

/**
 * @author 丁利军
 * @date 2025年10月11日 21:17
 * @description 自定义时间(小时:分钟)序列化器
 */

public class LocalTimeListSerializer extends JsonSerializer<List<LocalTime>> {
    private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("HH:mm");

    @Override
    public void serialize(List<LocalTime> value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
        gen.writeStartArray();
        for (LocalTime time : value) {
            gen.writeString(time.format(formatter));
        }
        gen.writeEndArray();
    }
}

